package com.dongdong.controller;


import com.dongdong.model.TbItem;
import com.dongdong.result.Result;
import com.dongdong.result.ResultConstant;
import com.dongdong.service.OrdersService;
import com.dongdong.vo.AddressVO;
import com.dongdong.vo.OrderVO;
import com.dongdong.vo.PayVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @GetMapping("/submitOrder")
    public Result submitOrder(@RequestHeader String token, @RequestParam String paymentType,@RequestParam Long addrId ){
        PayVO payVO = ordersService.submitorder(token, paymentType, addrId);
        return Result.OK().setData(payVO);
    }


    //增加
    @PostMapping("add")
    public Result add(@RequestHeader String token,@RequestBody AddressVO addressVO){
        ordersService.insertaddressVO(addressVO,token);
        return new Result(ResultConstant.SUCCESS_CODE, ResultConstant.SUCCESS_MSG); //4：操作成功
    }

    // 更改订单状态 order表
    @PostMapping("/updateOrder")
    public void updateOrder(@RequestParam String out_trade_no,@RequestParam String trade_no,@RequestParam String trade_status ){

        ordersService.updateOrder(out_trade_no,trade_no,trade_status);

        }


    //退款后修改订单状态
    @PostMapping("/UpdateRefundQuery")
    public void UpdateRefundQuery(@RequestParam String outTradeNo ){

        ordersService.UpdateRefundQuery(outTradeNo);

    }


    // 通过用户id查看所有订单 order表
    @GetMapping("/selectAllByUsername")
    public List<OrderVO> selectAllByUsername(@RequestParam String id ){
        List<OrderVO>  orderVOList=ordersService.selectAddressByUsername(id);
        return orderVOList;

    }

}
